package com.yueqian.utils;

import oracle.net.aso.MD5;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Test {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("md5");
        String src = "abc2";
        byte[] digest = md.digest(src.getBytes());
        System.out.println(new String(digest));
        //�P�<�O�֖?}(�r
        //�P�<�O�֖?}(�r
        //c�+Ue���.��9%C
        /*
        md5加密:名文相同,密码就一定相同;md5加密后是无法解密的;
        彩虹表:
            abc----�P�<�O�֖?}(�r
        md5加盐: 加密后加盐的操作:明文相同,两次加密后密码不一样,如果校验密码相同呢?
        加盐后生成的密码虽然不一样,但在某些密码段记录了盐的密文,
        对盐的密文进行解密后就知道加的什么盐,也就能对应找到真正的密码
         */
        BCryptPasswordEncoder bcpe = new BCryptPasswordEncoder();
        String abc = bcpe.encode("zs");
        System.out.println(abc);
        //$2a$10$ktcLglXcC8w9GTKxlW669OWwRb48Ynv4T9OgSSFuDgb/chvo0YRIe
        //$2a$10$zgztpHVxThLsyv0a1qbXZOxc5STmcOTMb8cUtd9V.rnt/DvZJgG6.
    }
}
